<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>中心医院医疗服务系统</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/lmb_style.css"/>">
<style>
	ul,li{
		padding: 0px;
		margin: 0px;
		list-style: none;
	}
	li{
		height:25px;
	}
</style>	
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>

</head>
<body>
	<script src="<c:url value="/js/jquery-migrate-1.1.0.min.js"/>"></script>
	<script type="text/javascript" src="<c:url value="/js/jquery.jqprint-0.3.js"/>"></script>
	<script type="text/javascript">
		//提交入库
		$("#hr_btn_ok").linkbutton({onClick: function(){		
			var type=$("#hr_type").combobox("getText");
			var value = $("#hr_serach").searchbox("getValue");
			console.log("value:"+value);
			console.log(type);			
			$.getJSON("to_findCouPurById", {"value": value}, function(data){				
	    		if(data.cpRsStatus=='已入库'){
	    			$.messager.alert('提示', "该订单已经入库！");
	    		}else{
	    			var url = (type == '采购入库' ? 'to_lmb_doHr' : '');	
	    			var lmb_hr = $("#lmb_hr");
	    			//提交表单			
	    			lmb_hr.form('submit', {
	    				url: url,		    
	    			    success: function(v){
	    					$.messager.alert('提示', "提交成功");	
	    					//关闭窗口
	    					$('#lmb_hr-win_add').window('close');
	    					//重新加载数据lmb_hcx
	    					$("#lmb-hr_t").datagrid("reload");
	    					$(this).form("clear");
	    					$('#lmb_hr_dg').datagrid('loadData', { total: 0, rows: [] }); 
	    				}	
	    			});
	    		}    		
	    	});	
			
		}});	
		
		$(function(){
			$("#hr_add").linkbutton({onClick:function(){						
				$("#lmb_hr-win_add").window("open");
				$("#lmb_hr").form("clear");
				var item = $('#lmb_hr_dg').datagrid('getRows');  
	            if (item) {  
	                for (var i = item.length - 1; i >= 0; i--) {  
	                    var index = $('#lmb_hr_dg').datagrid('getRowIndex', item[i]);  
	                    $('#lmb_hr_dg').datagrid('deleteRow', index);  
	                }  
	            } 
			}});
			
			//搜索采购单
			$('#hr_serach').searchbox({					
				searcher:function(value,name){	
				   if(value!=null){
				     console.log('llll'+value);
				     $("#lmb_hr_dg").datagrid({		    			
						url:'to_findPZDH',
						method:'post',
						queryParams:{
							n:value
						}			    		
					})					
				     $("#lmb_hr_dg").datagrid("reload");
				     $('#lmb_hr_dg').datagrid({
				    	 onLoadSuccess:function(data){  
						    if(data.total > 0){
						    	$('#hr_btn_ok').linkbutton('enable');
						    }else{
						    	$(this).datagrid('appendRow', { pdId: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'pdId', colspan: 8 });
							    $("#hr_btn_ok").linkbutton('disable');
								//隐藏分页导航条，这个需要熟悉datagrid的html结构，直接用jquery操作DOM对象，easyui datagrid没有提供相关方法隐藏导航条  
								//$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();  
								//如果通过调用reload方法重新加载数据有数据时显示出分页导航容器  
								//$(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();  
						    }		    
						 }						    
				     });  
				  }				    	
				}
			});
			
			//日期转换
			function lmb_rk_todate(value){
	            if(value){
					var date = new Date(value);  
	                return date.toLocaleDateString();
				}
	        }
			
			$("#hr_xq").linkbutton({onClick:function(){											
				var rows = $("#lmb-hr_t").datagrid("getSelections");
				if(rows.length == 1){	  
					$("#lmb-hrDet-window").window("open");
					var msId = rows[0].msId;
					$.getJSON("to_queryMaterialStorage", {"msId": msId}, function(data){
						$("#lmb-hrDet-rkdh").linkbutton({text: data.msId});
						$("#lmb-hrDet-pzdh").linkbutton({text: data.msVoucherId});
						$("#lmb-hrDet-rklx").linkbutton({text: data.msType});
						$("#lmb-hrDet-rksj").linkbutton({text: lmb_rk_todate(data.msDate)});
						$("#lmb-hrDet-jbr").linkbutton({text: data.jbrName});
						$("#lmb-hrDet-ck").linkbutton({text: data.ckName});		
					});	
					 //根据id查看详情	
					 $("#lmb-hrDet-dg").datagrid({
						url:'to_findMatStorDetailsByMsdMsId',
						width: '100%',
						queryParams:{					
							msId: msId,
			    			page:1, 
			    			rows:10
						}
					});
				}else{
					$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
				}
			}});

			//打印
			/*function printhrdivLmb(printpage){ 
				//获得当前页面body里面的内容
				var bodyHtml = document.body.innerHTML;
				//把打印的内容填充
				document.body.innerHTML = printpage; 
				//打印
				window.print(); 				
				//把body的内容还原				
				document.body.innerHTML = bodyHtml; 
				return true;

			}
			//点击按钮打印
			$("#lmb-hrDet-print").linkbutton({
				onClick: function(){
					var printpage = $('#lmb-hrDet-printArea').html();
					printhrdivLmb(printpage);
				}
			});	*/
			//点击按钮打印
			$("#lmb-hrDet-print").linkbutton({
				onClick: function(){
					$("#lmb-hrDet-printArea").jqprint();
				}
			});
			//根据日期搜索
			$("#hr_rqsearch").linkbutton({
				onClick:function(){
					var ksrq=$("#hr_ksrq").datebox("getText");
					var jsrq=$("#hr_jsrq").datebox("getText");
					$("#lmb-hr_t").datagrid({
						url:'to_findMaterialStorageByDate',
						method:'post',
						queryParams : {
							page:1, 
					    	rows:10,
							ksrq:ksrq,
							jsrq:jsrq
						}
					});
				}
			});
			
		});	
	</script>
	<table id="lmb-hr_t" class="easyui-datagrid" data-options="
			url:'to_queryAllMaterialStorage',
			fitColumns:true,fit:true,
			pagination: true,
			pageSize: 5,
			pageList: [5, 10, 15, 20],
			rownumbers: true,
			toolbar: '#lmb-hr_d',
			border:false
			">
		<thead>
			<tr>
				<th data-options="field:'',checkbox:true"></th>			
				<th data-options="field:'msVoucherId',width:'20%'">凭证单号</th>
				<th data-options="field:'msType',width:'14%'">入库类型</th>									
				<th data-options="field:'msDate',width:'14%',
						formatter:function(value){
                          if(value){
							var date = new Date(value);  
                            return date.toLocaleDateString();
						  }
                 }">入库时间</th>
				<th data-options="field:'msId',width:'20%'">入库单号</th>
				<th data-options="field:'jbrName',width:'15%'">经办人</th>					
                <th data-options="field:'ckName', width:'15%'">仓库</th>
			</tr>
		</thead>
	</table>
	
	<div id="lmb-hr_d">
		<a id="hr_add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加入库单</a>
		<a id="hr_xq" class="easyui-linkbutton" data-options="iconCls:'icon-xiangqing',plain:true">入库详情</a>	
		<input id="hr_ksrq" class="easyui-datebox" name="" data-options="
			label:'起止日期:',
			labelAlign:'right',
			width:'20%'	
		">
		- <input id="hr_jsrq"  class="easyui-datebox" name="">	
		<a id="hr_rqsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>	
	</div> 
	<div id="lmb_hr-win_add" class="easyui-window" title="耗材入库" data-options="collapsible:true,minimizable:false,maximizable:true,modal:true,iconCls:'icon-save',closed: true" style="width:800px;height:320px;padding:5px;">
		<form id="lmb_hr" method="post">
		<table width="100%" style="background: rgb(236,243,255); padding: 10px; border-radius: 5px;">
			<tr>
				<td width="50%">
					<input id="hr_serach" class="easyui-searchbox" name="matStorage.msVoucherId"
					data-options="label:'凭证单号', width: '70%', prompt: '请输入凭证单号'"/>
				</td>
				<td width="50%">
					<select id="hr_type" class="easyui-combobox" name="matStorage.msType" data-options="label: '入库类型',width: '70%',panelHeight: 'auto'">
						<option>采购入库</option>
						<option>还回入库</option>
					</select>
				</td>					
			</tr>
			<tr>
				<td>
					<select id="hr_ck" name="matStorage.msStatus" class="easyui-combogrid" 
							    data-options="	
							    required:true,			 
							    label: '仓 库',
							    width:'70%',
							    panelWidth:288,
							    idField:'storeId',
							    textField:'storeName',
							    url: 'queryAllStorehouse',
								pagination: true,
								pageSize: 8,
								pageList: [8, 16, 24, 32],
								idField: 'storeId',
								textField: 'storeName',
								columns: [[				
									{field:'storeName',title:'仓库名',width:100},
									{field:'storeKind',title:'类型',width:85},
									{field:'storeAddress',title:'地址',width:100}
								]]
					"></select>
				</td>
				<td >
						<select id="hr_jbr" name="matStorage.msOperator" class="easyui-combogrid" 
							    data-options="
							    required:true,
							    label: '经办人',	
							    width:'70%',
							    panelWidth:288,
							    required:true,
							    url: 'queryAllStaff',
								pagination: true,
								pageSize: 8,
								pageList: [8, 16, 24, 32],
								idField: 'staffNo',
								textField: 'staffName',
								columns: [[
									{field:'staffName',title:'姓名',width:100},
									{field:'departmentName',title:'部门',width:85},
									{field:'postName',title:'职务',width:100}
								]]
						"></select>
					</td>
			</tr>
		</table>		
	
	<div style="margin: 5px;height:100%;" >
			<div id="lmb_hr_tt" class="easyui-tabs" style="width:100%;margin-top:10px;"
				data-options="plain:true,narrow:true">
				<div title="详情明细" style="padding:10px;">
					<table id="lmb_hr_dg" class="easyui-datagrid" style="height:auto"
						data-options="
							iconCls:'icon-edit',
							singleSelect: true,
							width: '100%'
						">
						<thead>
							<tr>								
								<th data-options="field:'pdId',width:'17%'">详情编号</th>						
								<th data-options="field:'pdCId',width:'14%'">耗材编号</th>
								<th data-options="field:'pdName',width:'20%'">耗材名称</th>				
								<th data-options="field:'pdBatchNum',width:'13%'">批号</th>		
								<th data-options="field:'pdNum',width:'7%'">数量</th>		
								<th data-options="field:'pdNorms',width:'7%'">规格</th>
								<th data-options="field:'pdProductDate', width:'12%',
										formatter:function(value){
				                        if(value){
											var date = new Date(value);  
				                            return date.toLocaleDateString();
										}
				                 }">生产日期</th>
				                 <th data-options="field:'pdValidTill', width:'12%',
										formatter:function(value){
				                          if(value){
											var date = new Date(value);  
				                            return date.toLocaleDateString();
										}  
				                 }">有效期</th>
								
							</tr>
						</thead>
					</table>					
				</div>
			</div>
			<div style="margin-top: 10px;">
				<a id="hr_btn_ok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">确定入库</a>
			</div>		
		</div>
		</form>
	</div>
	
	
	
	<div id="lmb-hrDet-window" class="easyui-window" title="入库详情" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:'800px';height:70%;">		
		<div class="easyui-layout" style="padding:0px;" data-options="fit:true">			
			<div id="lmb-hrDet-printArea" data-options="region:'center'" style="padding:5px;border-top:none;border-left:none;border-right:none;">			
				<form id="lmb_hrDet_form" method="post">
					<h1 style="text-align: center">耗材入库记录</h1>
					<table width="100%">
						<tr>
							<td>入库单号: <a id="lmb-hrDet-rkdh" name="msId"         class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>凭证单号: <a id="lmb-hrDet-pzdh" name="msVoucherId"  class="easyui-linkbutton" data-options="plain:true,"></a></td>
							<td>入库类型: <a id="lmb-hrDet-rklx" name="msType"       class="easyui-linkbutton" data-options="plain:true"></a></td>					
						</tr>
						<tr>
							<td>入库时间: <a id="lmb-hrDet-rksj" name="msDate"      class="easyui-linkbutton" data-options="plain:true"></a></td>														
							<td>经办人:  <a id="lmb-hrDet-jbr"  name="msOperator"   class="easyui-linkbutton" data-options="plain:true"></a></td>
							<td>仓库:   <a id="lmb-hrDet-ck"   name="msStatus"      class="easyui-linkbutton" data-options="plain:true"></a></td>							
						</tr>			
					</table>						
					<div style="margin: 5px;">
						<table id="lmb-hrDet-dg" class="easyui-datagrid" 
							data-options="
								iconCls: 'icon-edit',
								singleSelect: true,										
								width: '100%'						
						">			
							<thead>
								<tr>		
									<th data-options="field:'msdCName',width:'26%',align:'center'">耗材名称</th>
									<th data-options="field:'msdBatchNum',width:'18%',align:'center'">批号</th>					
									<th data-options="field:'msdNorms',width:'15%',align:'center'">规格</th>
									<th data-options="field:'msdNum',width:'13%',align:'center'">数量</th>
									<th data-options="field:'msdProductDate',width:'15%',align:'center',
										formatter:function(value){
				                        if(value){
											var date = new Date(value);  
				                            return date.toLocaleDateString();
										}
									}">生产日期</th>
									<th data-options="field:'msdValidTill',width:'15%',align:'center',
										formatter:function(value){
				                        if(value){
											var date = new Date(value);  
				                            return date.toLocaleDateString();
										}
										
									}">有效期</th>
								</tr>
							</thead>
						</table>									
					</div>
				</form>				
			</div>
					
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="lmb-hrDet-print"  class="easyui-linkbutton" data-options="iconCls:'icon-print', plain:true">打印</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#lmb-hrDet-window').window('close');">取消</a>
			</div>			
		</div>]
	</div>		
</body>
</html>